package com.mybatisflex.example.controller;

import com.mybatisflex.example.pojo.domain.taos.Temperature;
import com.mybatisflex.example.pojo.entity.BizResult;
import com.mybatisflex.example.service.TemperatureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "气温API")
@Slf4j
@RequestMapping("/temperature")
@RestController
public class TemperatureController {

    @Autowired
    private TemperatureService temperatureService;


    @Operation(summary = "新增气温记录")
    @PostMapping(value = "/save")
    public BizResult<Temperature> save(@RequestBody Temperature temperature) {
        temperatureService.saveOne(temperature);
        return BizResult.create(temperature);
    }

    @Operation(summary = "查询气温记录")
    @GetMapping(value = "/query")
    public BizResult<List<Temperature>> query(@RequestParam(required = false) Integer districtCode,
                                              @RequestParam(required = false) String districtName) {
        List<Temperature> list = temperatureService.query(districtCode, districtName);
        return BizResult.create(list);
    }
}
    